{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Querying the Result of a Workflow (Lattice)\n",
    "\n",
    "Use the dispatch ID to locate and view the result from a previously completed workflow. Print individual attributes of the result.\n",
    "\n",
    "### Prerequisites\n",
    "\n",
    "Define and dispatch a lattice: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import covalent as ct\n",
    "import time\n",
    "\n",
    "@ct.electron\n",
    "def add(x, y):\n",
    "    time.sleep(1)\n",
    "    return x + y\n",
    "\n",
    "@ct.electron\n",
    "def multiply(x, y):\n",
    "    return x * y\n",
    "\n",
    "@ct.lattice\n",
    "def workflow(x, y):\n",
    "    res_1 = add(x=x, y=y)\n",
    "    return multiply(x=res_1, y=y)\n",
    "\n",
    "dispatch_id = ct.dispatch(workflow)(x=2, y=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Retrieve the dispatch result object using `ct.get_result`. Set the `wait` parameter to `True` so that the Covalent server waits until the dispatch finishes before retrieving the result."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = ct.get_result(dispatch_id=dispatch_id, wait=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Print the attributes of the result object that you are interested in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Workflow execution status: COMPLETED\n",
      "Result: 15\n",
      "Inputs: {'args': [], 'kwargs': {'x': <covalent.TransportableObject object at 0x1060ae520>, 'y': <covalent.TransportableObject object at 0x1060ae850>}}\n",
      "Execution start time: 2023-02-01 19:56:16.391500\n",
      "Execution end time: 2023-02-01 19:56:17.563476\n"
     ]
    }
   ],
   "source": [
    "print(f\"Workflow execution status: {result.status}\")\n",
    "print(f\"Result: {result.result}\")\n",
    "print(f\"Inputs: {result.inputs}\")\n",
    "print(f\"Execution start time: {result.start_time}\")\n",
    "print(f\"Execution end time: {result.end_time}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### See Also\n",
    "\n",
    "[Querying the Results of All Tasks (Electrons) in a Workflow](./query_electron_execution_result.ipynb)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "f63e7985caea997504032bc67ebf6b6ff07db5420026db9c4de4a9a029ce747c"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
